import 'package:flutter/material.dart';

import 'Home.dart';
import 'Category.dart';
import 'Users.dart';
import 'Cart.dart';


class Tabs extends StatefulWidget{
  const Tabs({super.key});

  @override
  State<Tabs> createState() => _TabsState();
}


class _TabsState extends State<Tabs>{

  int _currentIndex = 0;
  // 要写一个List来存放Page 列表 ，，，同时必须和底部的Index数量一样
  List _pageList = [
    HomePage(),
    CategoryPage(),
    CartPage(),
    UserPage()
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
        title: Text("JD SHOP")
    ),
    body:  _pageList[_currentIndex],
    // 底部状态栏
    bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex, // 选中谁
        // 点击触发
        onTap: (index){
          // 更新选中的index
           setState(() {
               _currentIndex = index;
           });
        },
        type: BottomNavigationBarType.fixed, // 自适应
        items: [
    BottomNavigationBarItem(icon: Icon(Icons.home)
    , label: '首页')
    ,BottomNavigationBarItem(icon: Icon(Icons.category)
    , label: '分类')
      ,BottomNavigationBarItem(icon: Icon(Icons.shopping_cart)
          , label: '购物车')
      ,BottomNavigationBarItem(icon: Icon(Icons.people)
          , label: '我的')
    ]));
  }

}